package com.yh.correct.service.impl;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yh.correct.dao.IProjectMapper;
import com.yh.correct.model.Page;
import com.yh.correct.model.Personnel;
import com.yh.correct.model.Project;
import com.yh.correct.service.IProjectService;

/**
 * 实现矫正方案登记业务实现类
 * @author 陈帅
 *
 */

@Service
public class ProjectServiceImpl implements IProjectService{

	private static Logger logger = LogManager.getLogger(ProjectServiceImpl.class);
	
	@Autowired
	private IProjectMapper projectMapper;
	/**
	 *根据id查询矫正方案
	 * @throws Exception 
	 */
	@Override
	public Map<String,Object> getProject(Project p) throws Exception {
		// TODO Auto-generated method stub
		Map<String,Object> map=null;
		map=projectMapper.getProject(p);
		return map;
	}

	/**
	 *添加矫正方案
	 * @throws Exception 
	 */
	@Override
	public int addProject(Project p) throws Exception {
		// TODO Auto-generated method stub
		logger.error("添加矫正方案："+p);
		return projectMapper.addProject(p);
	}
	
	/**
	 *删除矫正方案
	 * @throws Exception 
	 */
	@Override
	public int delProject(Project p) throws Exception {
		// TODO Auto-generated method stub
		return projectMapper.delProject(p);
	}

	/**
	 *修改矫正方案
	 * @throws Exception 
	 */
	@Override
	public int editProject(Project p) throws Exception {
		// TODO Auto-generated method stub
		return projectMapper.editProject(p);
	}

	/**
	 *根据姓名,日期模糊查询矫正方案
	 * @throws Exception 
	 */
	@Override
	public Page getLikeProjects(Map<String,Object> condition) throws Exception {
		// TODO Auto-generated method stub
		Page page=new Page();
		page.setTotalNum(projectMapper.getLikeProjectsCount(condition));
		int pageSize = Integer.parseInt(String.valueOf(condition.get("pageSize")));
		page.setPageSize(pageSize);
		int curPageNum = Integer.parseInt(String.valueOf(condition.get("pageNum")));
		page.setCurPageNum(curPageNum);
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		page.setResult(projectMapper.getLikeProjects(condition));
		logger.debug("模糊查询个人谈话方案!");
		return page;
	}
	

	@Override
	public List<Personnel> getPersonnel(Personnel P) throws Exception {
		// TODO Auto-generated method stub

		return projectMapper.getPersonnel(P);
	}

	@Override
	public List<Map<String, Object>> getAllP() throws Exception {
		// TODO Auto-generated method stub
		return projectMapper.getAllP();
	}
	
	
	
	
}
